<?php
/**
 * Implements methods for ArrayAccess interface - Required in WordXmlDocument
 * @author cosmin.dorobantu <cdo@auximus.com>
 */
abstract class ObjectAccess implements ArrayAccess {
	/**
	 * The variable storage array
	 * 
	 * @var array
	 */
	private $_data = array ();
	
	/**
	 * ArrayAccess isset & empty implementation
	 *
	 * @param mixed $offset
	 * @return bool
	 */
	public function offsetExists($offset) {
		return (isset ( $this->_data [$offset] ) ? true : false);
	}
	
	/**
	 * ArrayAccess get implementation
	 *
	 * @param mixed $offset
	 * @return mixed
	 */
	public function offsetGet($offset) {
		return (isset ( $this->_data [$offset] ) ? $this->_data [$offset] : null);
	}
	
	/**
	 * ArrayAccess set implementation
	 *
	 * @param mixed $offset
	 * @param mixed $value
	 */
	public function offsetSet($offset, $value) {
		$this->_data [$offset] = $value;
	}
	
	/**
	 * ArrayAccess unset implementation
	 *
	 * @param mixed $offset
	 */
	public function offsetUnset($offset) {
		if (isset ( $this->_data [$offset] )) {
			unset ( $this->_data [$offset] );
		}
	}
	
	/**
	 * Retrieve values from data array
	 *
	 * @param mixed $key
	 * @return mixed
	 */
	public function getData($key = null) {
		if (is_null ( $key )) {
			return $this->_data;
		} else {
			return $this->offsetGet ( $key );
		}
	}
}